﻿Public Class FrmRegistrarContactoReferenciaCliente

    Private Sub picAtras_Click(sender As Object, e As EventArgs) Handles picAtras.Click
        For Each x As Control In Me.Parent.Controls.OfType(Of FrmRegistrarFotografiaCliente)()
            x.Visible = True
        Next
        Me.Visible = False
    End Sub

    Private Sub btnRegistrar_Click(sender As Object, e As EventArgs) Handles btnRegistrar.Click

        lblNombreC1Req.Visible = False
        lblApellidoC1Req.Visible = False
        lblTelefonoC1Req.Visible = False
        lblNombreC2Req.Visible = False
        lblApellidoC2Req.Visible = False
        lblTelefonoC2Req.Visible = False

        Dim requeridos As New List(Of TextBox)
        requeridos.Add(txtPrimerNombreC1)
        requeridos.Add(txtPrimerApellidoC1)
        requeridos.Add(txtTelefonoC1)
        requeridos.Add(txtPrimerNombreC2)
        requeridos.Add(txtPrimerApellidoC2)
        requeridos.Add(txtTelefonoC2)

        For Each txtBox As TextBox In requeridos
            If txtBox.Text = "" Then
                Select Case txtBox.Name
                    Case "txtPrimerNombreC1"
                        lblNombreC1Req.Visible = True
                    Case "txtPrimerApellidoC1"
                        lblApellidoC1Req.Visible = True
                    Case "txtTelefonoC1"
                        lblTelefonoC1Req.Visible = True
                End Select
            End If
        Next

        If txtPrimerNombreC2.Text <> "" Or txtSegundoNombreC2.Text <> "" Or txtPrimerApellidoC2.Text <> "" Or txtSegundoApellidoC2.Text <> "" Or
        txtTelefonoC2.Text <> "" Or txtCelularC2.Text <> "" Then
            For Each txtBox As TextBox In requeridos
                If txtBox.Text = "" Then
                    Select Case txtBox.Name
                        Case "txtPrimerNombreC2"
                            lblNombreC2Req.Visible = True
                        Case "txtPrimerApellidoC2"
                            lblApellidoC2Req.Visible = True
                        Case "txtTelefonoC2"
                            lblTelefonoC2Req.Visible = True
                    End Select
                End If
            Next
        End If


        Dim frm01 As New FrmRegistrarCliente
        For Each x As Control In Me.Parent.Controls.OfType(Of FrmRegistrarCliente)()
            frm01 = x
        Next

        Dim frm02 As New FrmRegistrarCredencialesCliente
        For Each x As Control In Me.Parent.Controls.OfType(Of FrmRegistrarCredencialesCliente)()
            frm02 = x
        Next

        Dim frm03 As New FrmRegistrarFotografiaCliente
        For Each x As Control In Me.Parent.Controls.OfType(Of FrmRegistrarFotografiaCliente)()
            frm03 = x
        Next

        Dim frm04 As New FrmRegistrarContactoReferenciaCliente
        For Each x As Control In Me.Parent.Controls.OfType(Of FrmRegistrarContactoReferenciaCliente)()
            frm04 = x
        Next

        If (txtPrimerNombreC1.Text <> "" And txtPrimerApellidoC1.Text <> "" And txtTelefonoC1.Text <> "") Or (txtPrimerNombreC2.Text <> "" And
            txtPrimerApellidoC2.Text <> "" And txtTelefonoC2.Text <> "") Then

            objGestorUsuario.RegistrarUsuario(frm01.txtPrimerNombre.Text, frm01.txtSegundoNombre.Text, frm01.txtPrimerApellido.Text, frm01.txtSegundoApellido.Text,
                                    frm01.txtIdentificacion.Text, frm01.txtNacionalidad.Text, frm01.txtAlias.Text, frm01.dateNacimiento.Text,
                                    frm01.txtCorreoElectronico.Text, frm03.fotografia, frm01.txtTelefono.Text, frm02.txtContrasena.Text,
                                    frm01.txtCelular.Text, DateTime.Now().ToShortDateString(), True, frm01.cbxTipoIdentificacion.SelectedValue, frm01.cbxGenero.SelectedValue,
                                    frm01.cbxObjetivo.SelectedValue, frm01.cbxRol.SelectedValue, frm02.txtNumeroCarne.Text)

            If frm04.txtPrimerNombreC1.Text.Length > 0 And frm04.txtPrimerApellidoC1.Text.Length > 0 And frm04.txtTelefonoC1.Text.Length > 0 Then
                objGestorUsuario.RegistrarContacto(frm04.txtPrimerNombreC1.Text, frm04.txtSegundoNombreC1.Text, frm04.txtPrimerApellidoC1.Text,
                                         frm04.txtSegundoApellidoC1.Text, frm04.txtTelefonoC1.Text, frm04.txtCelularC1.Text, 0)
            End If

            If frm04.txtPrimerNombreC2.Text.Length > 0 And frm04.txtPrimerApellidoC2.Text.Length > 0 And frm04.txtTelefonoC2.Text.Length > 0 Then
                objGestorUsuario.RegistrarContacto(frm04.txtPrimerNombreC2.Text, frm04.txtSegundoNombreC2.Text, frm04.txtPrimerApellidoC2.Text,
                                         frm04.txtSegundoApellidoC2.Text, frm04.txtTelefonoC2.Text, frm04.txtCelularC2.Text, 0)
            End If

            frmTransparente.Close()
            For Each frm As FrmClientes In FrmPrincipal.paneForm.Controls.OfType(Of FrmClientes)()
                frm.lista = objGestorUsuario.ObtenerUsuarios
                frm.tblClientes.DataSource = frm.lista
            Next

            Dim form As New frmRegistroExitoso 'crea una instancia del form 
            form.Dock = DockStyle.Fill
            frmTransparente.AgregarContenido(form)
            form.agregarLabels("del usuario " + frm01.txtPrimerNombre.Text + ".")
            frmTransparente.Show()
            Me.Hide()

            frmSecundario.Width = Screen.PrimaryScreen.WorkingArea.Width
            frmSecundario.Height = Screen.PrimaryScreen.WorkingArea.Height - Screen.PrimaryScreen.WorkingArea.Height * (60 / 100)
            frmSecundario.Location = New Point(Screen.PrimaryScreen.WorkingArea.X, Screen.PrimaryScreen.WorkingArea.Height * (32 / 100))

        End If

    End Sub

    Private Sub btnCancelar_Click(sender As Object, e As EventArgs) Handles btnCancelar.Click
        frmTransparente.Close()
    End Sub

End Class
